#
# Makefile for module.
#
CROSS		?= arm-linux-
NAME		:= buzzer_pwm

CC			:=$(CROSS)gcc
LD			:=$(CROSS)ld
OBJCOPY		:=$(CROSS)objcopy
OBJDUMP		:=$(CROSS)objdump
AR			:=$(CROSS)ar

MKHEADER	:=../tools/make_image/mkv210_image

INCDIR	:= $(shell pwd)/include
# C预处理器的flag，flag就是编译器可选的选项
CPPFLAGS	:= -nostdlib -nostdinc -I$(INCDIR)
# C编译器的flag
CFLAGS		:= -Wall -O2 -fno-builtin

#导出这些变量到全局，其实就是给子文件夹下面的Makefile使用
export CC LD OBJCOPY OBJDUMP AR CPPFLAGS CFLAGS

OBJS := start.o led.o clock.o uart.o main.o pwm.o
OBJS += lib/libc.a

$(NAME).bin: $(OBJS)
	@echo [LD] $^
	@$(LD) -Tlink.lds -o $(NAME).elf $^
	@echo [OC] Objcopying $@
	@$(OBJCOPY) -O binary $(NAME).elf $(NAME).bin
	@echo [OD] Objdumping $@
	@$(OBJDUMP) -D $(NAME).elf > $(NAME)_elf.dis
	@echo make header information for irom booting
	@$(MKHEADER) $(NAME).bin

lib/libc.a:
	@cd lib;	make;	cd ..
	
%.o : %.S
	@echo [CC] $<
	@$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< -c

%.o : %.c
	@echo [CC] $<
	@$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< -c

clean:
	rm *.o *.elf *.bin *.dis mkx210 -f
	cd lib; make clean; cd ..
